﻿<?php
$edit_url	=	"?act=list_singer";
if ($del_id) {
	acp_check_permission('del_singer');
	if ($_POST['submit']) {
		$mysql->query("DELETE FROM ".$tb_prefix."singer WHERE singer_id = '".$del_id."'");
		echo "Đã xóa xong <meta http-equiv='refresh' content='0;url=".$edit_url."'>";
		exit();
	}
	?><table align=center><form method="post">Bạn có muốn xóa không ??????<br><center><input value="Có" name=submit type=submit class=submit></center></form></table><?
}
if($mode == 'edit') {
acp_check_permission('edit_singer');
	if(is_numeric($id)) {
		$sql	=	"SELECT * FROM ".$tb_prefix."singer WHERE singer_id = $id";
		$query	=	$mysql->query($sql);
		$row	=	$mysql->fetch_array($query);
		$singer_NAME	=	$row['singer_name'];
		$singer_IMG		=	$row['singer_img'];
		$singer_TYPE	=	$row['singer_type'];
		$singer_INFO	=	$row['singer_info'];
		$action			=	"?act=singer&mode=edit&id=$id";
			if(isset($_POST['submit'])) {
				if($_POST['name'] == "") {
					echo " Bạn chưa nhập đủ thông tin ";
				}
				else {
					$singer		=	m_htmlchars(stripslashes(trim(urldecode($_POST['name']))));
					$singer_ascii	=	strtolower(utf8_to_ascii($singer));
					$img		=	$_POST['img'];
					$type		=	$_POST['singer_type'];
					$info		=	$_POST['info'];
					$mysql->query("UPDATE ".$tb_prefix."singer SET
						singer_name			=  	'".$singer."',
						singer_name_ascii 	= 	'".$singer_ascii."',
						singer_img			= 	'".$img."',
						singer_type			= 	'".$type."',
						singer_info			= 	'".$info."'
						WHERE singer_id 	= 	'".$id."'");
				echo "<script language='JavaScript'>{ window.parent.location='?act=singer&mode=edit&id=$id' }</script>";
				}
			}
		}
include("templates/singer.html");
}
if($mode == 'add') {
acp_check_permission('add_singer');
	if(isset($_POST['submit'])) {
		if($_POST['name'] == "") {
			echo "Bạn chưa nhập đủ thông tin. <a href=\"javascript:history.go(-1);\">Trở về trang trước </a>";
		}
		else {
			$singer			=	m_htmlchars(stripslashes(trim(urldecode($_POST['name']))));
			$singer_ascii	=	strtolower(utf8_to_ascii($singer));
			$img			=	$_POST['img'];
			$type			=	$_POST['singer_type'];
			$info			=	$_POST['info'];
			$action		 	= "?act=singer&mode=add";
			$mysql->query("INSERT INTO ".$tb_prefix."singer (singer_name,singer_name_ascii,singer_img,singer_type,singer_info) 
						 VALUES ('".$singer."','".$singer_ascii."','".$img."','".$type."','".$info."')");
			echo "<script language='JavaScript'>{ window.parent.location='?act=list_singer' }</script>";
		}
	}
include("templates/singer.html");
}
?>